package com.zkhz.base.security.authentication.userdetails.model;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;
import java.util.Map;

/**
 * 认证用户
 * 注意：这里的username属性是登录名，而不是用户姓名
 * @author wuzeqin
 * @date 2020/5/28
 **/
public class SecurityUserDetails extends User implements Cloneable {

    private final Map<String, String> userInfo;

    public SecurityUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities, Map<String, String> userInfo) {
        this(username, password, true, true, true, authorities, userInfo);
    }

    public SecurityUserDetails(String username, String password, boolean enabled, boolean accountNonExpired, boolean accountNonLocked,
                               Collection<? extends GrantedAuthority> authorities, Map<String, String> userInfo) {
        super(username, password, enabled, accountNonExpired, accountNonExpired, accountNonLocked, authorities);
        this.userInfo = userInfo;
    }

    @Override
    public SecurityUserDetails clone() throws CloneNotSupportedException {
        return (SecurityUserDetails) super.clone();
    }

    public Map<String, ?> getUserInfo() {
        return userInfo;
    }
}
